//
//  DRExtraMealVC.m
//  DoctorRen
//
//  Created by Lemon on 2018/11/28.
//

#import "DRExtraMealVC.h"
#import "DRExtraMealCell.h"

@interface DRExtraMealVC ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIButton *closeButton;
@property (weak, nonatomic) IBOutlet UIButton *sureButton;
@property (weak, nonatomic) IBOutlet UIView *backView;

@property (nonatomic, assign) NSInteger selectIndex;
@end

@implementation DRExtraMealVC

-(void)viewDidLoad{
    [super viewDidLoad];
    self.tableView.bounces = NO;
    self.selectIndex = 0;
    self.backView.layer.cornerRadius = 10;
    self.backView.layer.masksToBounds = YES;
    
}
- (IBAction)clickCloseBtn:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}
- (IBAction)clickSureButton:(id)sender {
    if (self.selected) {
        self.selected(self.selectIndex);
    }
    [self dismissViewControllerAnimated:YES completion:nil];

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DRExtraMealCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DRExtraMealCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row == 0) {
        cell.titleLB.text = @"早餐加餐";
        cell.coverIV.image = [UIImage imageNamed:@"早餐"];
    }else if (indexPath.row == 1){
        cell.titleLB.text = @"中餐加餐";
        cell.coverIV.image = [UIImage imageNamed:@"午餐"];
    }else{
        cell.titleLB.text = @"晚餐加载";
        cell.coverIV.image = [UIImage imageNamed:@"晚餐"];
    }
    cell.selectIV.image = [UIImage imageNamed:indexPath.row == self.selectIndex ? @"小图标_单选_选中" : @"小图标_单选_未选"];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    self.selectIndex = indexPath.row;
    [self.tableView reloadData];
}

@end
